/**
 * @file engineer_mode_firmware_version.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_watch.h"

#if USE_LV_WATCH_ENGINEER_MODE != 0

#if 0

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
***********************/
lv_obj_t * engineer_mode_firmware_version_create(lv_obj_t * activity_obj)
{
    lv_obj_t * obj;
    if(activity_obj == NULL) {
        lv_watch_activity_ext_t activity_ext;
        memset(&activity_ext, 0, sizeof(lv_watch_activity_ext_t));
        activity_ext.actId = ACT_ID_ENGINEER_MODE_FW_VERSION;
        activity_ext.create = engineer_mode_firmware_version_create;
        activity_ext.prepare_destory = NULL;
        activity_obj = lv_watch_creat_activity_obj(&activity_ext);
        LV_ASSERT_MEM(activity_obj);
        if(NULL == activity_obj) {
            return NULL;
        }
    }

    obj = lv_watch_obj_create(activity_obj);
    LV_ASSERT_MEM(obj);
    if(NULL == obj) {
        return NULL;
    }

    lv_obj_t * title = lv_label_create(obj, NULL);
    lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
    lv_label_set_long_mode(title, LV_LABEL_LONG_SROLL);
    lv_obj_set_size(title, LV_HOR_RES, LV_VER_RES / 4);
    lv_label_set_text_id(title, WATCH_TEXT_ID_ENGINEER_MODE_FIRMWARE_VERSION);
    lv_obj_add_style(title, LV_LABEL_PART_MAIN, &lv_watch_font30);
    lv_obj_align(title, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);

    lv_obj_t * cont = lv_cont_create(obj, NULL);
    lv_obj_add_style(cont, LV_OBJ_PART_MAIN, &lv_style_transp_fit);
    if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL)
        lv_btn_set_layout(cont, LV_LAYOUT_COLUMN_RIGHT);
    else
        lv_btn_set_layout(cont, LV_LAYOUT_COLUMN_LEFT);
    lv_obj_align(cont, NULL, LV_ALIGN_CENTER, -10, -20);
    lv_cont_set_fit2(cont, LV_FIT_TIGHT, LV_FIT_TIGHT);
    lv_obj_set_click(cont, false);

#if USE_LV_WLAN != 0
    if(0 < heron_fmacfw_len) {
        printf("%s: heron_fmacfw_len %d\n", __FUNCTION__, heron_fmacfw_len);
        for(uint32_t i = heron_fmacfw_len - 10;i > 0;i--) {
            if(('1' == heron_fmacfw[i])
               && ('.' == heron_fmacfw[i + 1])
               && ('.' == heron_fmacfw[i + 5])) {
                char wifi_fw_ver[10];
                strncpy(wifi_fw_ver, (char *)(&heron_fmacfw[i]), 9);
                wifi_fw_ver[9] = '\0';
                printf("%s: wifi_fw_ver %s\n", __FUNCTION__, wifi_fw_ver);
                lv_obj_t * label_wifi = lv_label_create(cont, NULL);
                lv_obj_add_style(label_wifi, LV_LABEL_PART_MAIN, &lv_watch_font20);
                lv_label_set_text(label_wifi, "Wifi: ");
                lv_label_ins_text(label_wifi, LV_LABEL_POS_LAST, wifi_fw_ver);
                break;
            }
        }
    }
#endif

#if (USE_LV_BLUETOOTH != 0) && (USE_LV_BT_CHIP_5803 != 0)
    if(0 < build_ram_only_len) {
        printf("%s: build_ram_only_len %d\n", __FUNCTION__, build_ram_only_len);
        for(uint32_t i = 0;i < build_ram_only_len - 14;i++) {
            if(('B' == build_ram_only[i])
               && ('T' == build_ram_only[i + 1])
               && ('D' == build_ram_only[i + 2])
               && ('M' == build_ram_only[i + 3])
               && ('_' == build_ram_only[i + 4])
               && ('.' == build_ram_only[i + 6])
               && ('.' == build_ram_only[i + 10])) {
                char bt_fw_ver[10] = {};
                strncpy(bt_fw_ver, (char *)&build_ram_only[i + 5], 9);
                bt_fw_ver[9] = '\0';
                printf("%s: bt_fw_ver %s\n", __FUNCTION__, bt_fw_ver);
                lv_obj_t * label_bt = lv_label_create(cont, NULL);
                lv_obj_add_style(label_bt, LV_LABEL_PART_MAIN, &lv_watch_font20);
                lv_label_set_text(label_bt, "Bt :");
                lv_label_ins_text(label_bt, LV_LABEL_POS_LAST, bt_fw_ver);
                break;
            }
        }
    }
#endif

    lv_obj_align(cont, obj, LV_ALIGN_CENTER, 0, 0);

    return obj;
}

#endif

#endif /*USE_LV_WATCH_ENGINEER_MODE*/
